package main;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import tools.StringTools;

public class TopicCentral {
   private final ConcurrentMap<String, String> topics;

   private static final TopicCentral INSTANCE = new TopicCentral();

   public static final TopicCentral getInstance() {
	  return INSTANCE;
   }

   private TopicCentral() {
	  topics = new ConcurrentHashMap<String, String>();
   }

   public void clearTopicMap() {
	  topics.clear();
   }

   /**
    * Prints the topic of the specified channel, to that channel
    * 
    * @param channel
    */
   public void getTopic(final String channel) {
	  String topic = topics.get(channel);
	  if (!StringTools.isNullOrEmpty(topic)) {
		 Bot.getInstance().sendMessage(channel, topic);
	  }
   }

   public void setTopic(final String channel, final String topic) {
	  if (StringTools.isNullOrEmpty(channel) || StringTools.isNullOrEmpty(topic))
		 throw new IllegalArgumentException();
	  topics.put(channel, topic);
   }
}
